﻿using A.M.ETO;
using L.M.System.Application.IServices;
using L.M.System.Application.Services;
using L.M.System.Domain.DTO;
using L.M.System.Domain.Entity;
using L.M.System.Infrastruecure.Repository;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Cryptography;

namespace L.M.System.Read.API.Controllers
{
    /// <summary>
    /// 角色
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Role_listReadController : ControllerBase
    {
        private readonly IRole_listServices role_ListServices;
        public Role_listReadController(IRole_listServices role_ListServices)
        {
            this.role_ListServices = role_ListServices;
        }

        /// <summary>
        /// 角色显示
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <param name="rName">查询条件</param>
        /// <returns>角色显示</returns>
        [HttpGet]
        public async Task<IActionResult> GteRoleInfor(int pageSize, int pageIndex, string? rName)
        {
            return Ok(await role_ListServices.GteRoleInfor(pageSize, pageIndex, rName));
        }

        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="roleAdd">角色实体</param>
        /// <returns>角色</returns>
        [HttpPost]
        public async Task<IActionResult> GetAddRoelInfor(RoleAddDTO roleAdd)
        {
            return Ok(await role_ListServices.GetAddRoelInfor(roleAdd));
        }

        /// <summary>
        /// 获取角色下面所有的人员
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="pageIndex">当前页索引</param>
        /// <param name="tName">查询条件</param>
        /// <returns>统一返回格式</returns>
        [HttpGet]
        public async Task<IActionResult> GetShowRoleTrue(int pageSize, int pageIndex, string? tName)
        {
            return Ok(await role_ListServices.GetShowRoleTrue(pageSize, pageIndex, tName));
        }

        /// <summary>
        /// 修改 角色的状态 + 角色主权限添加 + 角色二级权限添加 + 角色按钮添加
        /// </summary>
        /// <param name="roleDTO">角色等权限DTO</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> AddInforRole(AddInforRoleDTO roleDTO)
        {
            return  Ok(await role_ListServices.AddInforRole(roleDTO));
        }

        /// <summary>
        /// 获取所有未启用的角色
        /// </summary>
        /// <returns>获取所有未启用的角色</returns>
        [HttpGet]
        public async Task<IActionResult> GetFalstRole()
        {
            var list = await role_ListServices.GetShowQueryableAsync(c => !c.role_status);
            return Ok(list.ToList());
        }

        /// <summary>
        /// 获取所有的用户 及 关联的角色
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="sName"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetStaff_RoleInfor(int pageSize, int pageIndex, string? sName)
        {
            return Ok(await role_ListServices.GetStaff_RoleInfor(pageSize, pageIndex, sName));
        }

        /// <summary>
        /// 获取所有的角色
        /// </summary>
        /// <returns>获取所有的</returns>
        [HttpGet]
        public async Task<IActionResult> GetShowRole()
        {
            return Ok(await role_ListServices.GetShowInforAsync());
        }

        /// <summary>
        /// 获取角色的备注
        /// </summary>
        /// <param name="rId"></param>
        /// <returns>summary</returns>
        [HttpGet]
        public IActionResult GetRoleInfor(string? rId)
        {
            return Ok(role_ListServices.GetRoleInfor(rId));
        }


        /// <summary>
        /// (修改)修改 角色的状态 + 角色主权限添加 + 角色二级权限添加 + 角色按钮添加
        /// </summary>
        /// <param name="roleDTO">角色等权限DTO</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> UpdInforRole(AddInforRoleDTO roleDTO)
        {
            return Ok(await role_ListServices.UpdInforRole(roleDTO));
        }

        /// <summary>
        /// 获取到登录用户的信息
        /// </summary>
        /// <param name="uId">用户编号</param>
        /// <returns>获取到登录用户的信息</returns>
        [HttpGet]
        public async Task<IActionResult> GetShowStaaInfor(string? uId)
        {
            return Ok(await role_ListServices.GetShowStaaInfor(uId));
        }

        /// <summary>
        /// 禁用不存在用户的角色
        /// </summary>
        /// <param name="rId">编号</param>
        /// <returns>统一返回格式</returns>
        [HttpPut]
        public async Task<IActionResult> UpdStaty(string rId)
        {
            return Ok(await role_ListServices.UpdStaty(rId));
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="rId">编号</param>
        /// <returns>统一返回格式</returns>
        [HttpDelete]
        public async Task<IActionResult> DelInforRole(string? rId)
        {
            return Ok(await role_ListServices.DelInforRole(rId));
        }


        /// <summary>
        /// 反填角色
        /// </summary>
        /// <param name="rId">编号</param>
        /// <returns>统一返回格式</returns>
        [HttpGet]
        public async Task<IActionResult> FanInforRole(string rId)
        {
            return Ok(await role_ListServices.FanInforRole(rId));
        }

        /// <summary>
        /// 修改角色用户
        /// </summary>
        /// <param name="roleUpd">角色</param>
        /// <returns>修改角色用户</returns>
        [HttpPost]
        public async Task<IActionResult> GetUpdRoleInfor(RoleAddDTO roleUpd)
        {
            return Ok(await role_ListServices.GetUpdRoleInfor(roleUpd));
        }

        /// <summary>
        /// 获取所有启用的角色
        /// </summary>
        /// <returns>获取所有启用的角色</returns>
        [HttpGet]
        public async Task<IActionResult> GetTrueRole()
        {
            var list = await role_ListServices.GetShowQueryableAsync(c => c.role_status == true);
            return Ok(list.ToList());
        }
    }
}
